package com.frxuexi.mdm2202.ui.demo

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.CheckCircle
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import com.frxuexi.mdm2202.R

data class MyInfo(val img: Int, val title: String, val content: String)

@OptIn(ExperimentalLayoutApi::class)
@Preview
@Composable
fun MyListPage() {
    val list = mutableListOf<MyInfo>()
    for (i in 1..20) {
        list.add(MyInfo(R.drawable.ic_launcher_background, "张三$i", "这是我的描述$i"))
    }
    LazyColumn(content = {
        items(list) { info ->
            ListItem(info)
        }
    })
    /*LazyVerticalGrid(columns = GridCells.Fixed(2), content = {
        items(list){info->
            ListItem(info)
        }
    })*/

    /*LazyVerticalStaggeredGrid(columns = StaggeredGridCells.Fixed(2), content = {
        items(list){info->
            ListItem(info)
        }
    })*/

    /*FlowRow(modifier = Modifier.padding(8.dp),horizontalArrangement=Arrangement.spacedBy(10.dp),
        verticalArrangement = Arrangement.spacedBy(10.dp)) {
        ChipItem("Price: High to Low")
        ChipItem("Avg rating: 4+")
        ChipItem("Free breakfast")
        ChipItem("Free cancellation")
        ChipItem("£50 pn")
    }*/
}

@Composable
fun ChipItem(str: String) {
    Text(
        text = str,
        modifier = Modifier
            .border(1.dp, Color.Gray, RoundedCornerShape(50))
            .background(Color.LightGray, RoundedCornerShape(50))
            .padding(20.dp)
    )
}


@Composable
fun ListItem(info: MyInfo) {
    Row(
        Modifier
            .height(100.dp)
            .padding(horizontal = 20.dp)
            .padding(top = 10.dp)
    ) {
        Box(contentAlignment = Alignment.BottomEnd) {
            /*Image(painter = painterResource(id = info.img), contentDescription = "",
                modifier = Modifier.clip(CircleShape))*/
            AsyncImage(
                model = "https://img0.baidu.com/it/u=3517553771,449336921&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1721322000&t=c93a79b44222bbfb70fa263903afb7a0",
                contentDescription = "",
                contentScale= ContentScale.Crop,//居中裁剪
                modifier = Modifier
                    .width(90.dp)
                    .height(90.dp)
                    .clip(CircleShape)
            )
            Icon(imageVector = Icons.Default.CheckCircle, contentDescription = "")
        }

        Column(
            Modifier
                .fillMaxHeight()
                .padding(start = 10.dp), verticalArrangement = Arrangement.SpaceAround
        ) {
            Text(text = info.title)
            Text(text = info.content)
        }
    }
}